package ch07;

import ch07.pojo.SysUser;
import ch07.service.SysUserService;
import org.apache.log4j.Logger;
import org.junit.Before;
import org.junit.Test;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.transaction.annotation.Transactional;

import java.text.ParseException;
import java.util.ArrayList;
import java.util.List;



public class SysUserTest {
    private Logger logger=Logger.getLogger(SysUserTest.class);

    @Before
    public void setUp()throws Exception{

    }

    @Test
    public void testGetUserList(){
        ApplicationContext ctx=new ClassPathXmlApplicationContext("applicationch07.xml");

        SysUserService userService= (SysUserService) ctx.getBean("sysUserService");

        List<SysUser> usersList=new ArrayList<>();

        SysUser userCondition=new SysUser();

//        userCondition.setRealName("赵");
//        userCondition.setRoleId(2);
        usersList=userService.getList(userCondition);

        System.out.println(usersList);
    }


    @Test
    @Transactional
    public void testAddUser() throws ParseException{
        ApplicationContext ctx=new ClassPathXmlApplicationContext("applicationch07.xml");
        SysUserService service= (SysUserService) ctx.getBean("sysUserService");

        SysUser user=new SysUser();
        user.setAccount("xiaoxiao");
        user.setRealName("红孩儿");
        user.setPassword("123456");
        user.setSex(1);
        user.setBirthday("2022-08-14");
        user.setPhone("12312341234");
        user.setAddress("湖南");
        user.setRoleId(1);
        user.setCreatedUserId(1);
        user.setCreatedTime("2013-03-21 16:52:07");

      boolean result= service.add(user);
      logger.debug("testAdd result:"+result);
    }
}
